/*
 * @Author: 管哥哥 1729207740@qq.com
 * @Date: 2025-08-13 15:58:54
 * @LastEditors: 管哥哥 1729207740@qq.com
 * @LastEditTime: 2025-09-12 11:18:15
 * @FilePath: \web\vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
        '@components': path.resolve(__dirname, './src/components'),
        '@utils': path.resolve(__dirname, './src/utils')
      }
    },
    server: {
      proxy: {
        '^/api': {
          target: env.VITE_API_URL || 'http://127.0.0.1:5050',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '/api')
        },
        '/geoserver': {
          target: 'http://localhost:8080/geoserver',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/geoserver/, '')
        },
        '/chat': {
          target: 'http://127.0.0.1:11434/api/chat',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/chat/, '')
        },
        '/completions': {
          // target: 'http://localhost/api/v1/chats_openai/e5c4c2ba815511f0b4df1a95ba474f59/chat/completions',
          target: 'http://localhost/api/v1/chats/e5c4c2ba815511f0b4df1a95ba474f59/completions',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/completions/, '')
        },
        '/globeWmts': {
          target: 'http://localhost:8000',
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/globeWmts/, '')
        }
      },
      watch: {
        usePolling: true,
        ignored: ['**/node_modules/**', '**/dist/**'],
      },
      host: '0.0.0.0',
    }
  }
})
